package com.jk.xz.dao;

import com.jk.AddressBean;
import com.jk.CinemaBean;
import com.jk.MovieHallBean;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface CinemaDao {
    //查询影院总条数
    Integer getCount(@Param("cinema") CinemaBean cinema);
    //查询影院
    List<CinemaBean> queryCinema(@Param("start") Integer start, @Param("rows") Integer rows, @Param("cinema") CinemaBean cinema);
    //根据影院id查询对应的影厅
    @Select("select t.*,c.cinema cinemaName from t_movie_hall t left join t_cinema c\n" +
            "on t.cinemaId=c.cinemaId\n" +
            "where t.cinemaId=#{id}")
    List<MovieHallBean> getHall(Integer id);
    //查询市
    @Select("select * from t_address where pid=0")
    List<AddressBean> getCity();
    //查询县/区
    @Select("select * from t_address where pid=#{countyId}")
    List<AddressBean> getCounty(Integer countyId);
    //新增影院
    void addCinema(CinemaBean cinema);
    //修改影院
    @Update("update t_cinema set cityId = #{city},pwd = #{pwd},countyId=#{countyId},cinema=#{cinema},cinemaSite=#{cinemaSite},cinemaImg=#{cinemaImg} where cinemaId=#{cinemaId}")
    void upCinema(CinemaBean cinema);
    //批删影院
    void delAll(String[] ids);
    //根据id回显影院
    @Select("          select t.*,c.city city2,c.county county2 from t_cinema t\n" +
            "            left join\n" +
            "          (select b1.addressId city, b.addressId county from  t_address b, t_address b1\n" +
            "           where b.pid=b1.addressId)c\n" +
            "           on t.countyId=c.county where t.cinemaId=#{id}")
    CinemaBean byId(Integer id);
    //查询影厅总条数
    Integer getHallCount(@Param("hall") MovieHallBean hall,@Param("id") Integer id);
    //查询影厅
    List<CinemaBean> queryHall(@Param("start") Integer start, @Param("rows") Integer rows, @Param("hall") MovieHallBean hall,@Param("id") Integer id);
    //新增影厅
    void addHall(MovieHallBean hall);
   //修改影厅
    @Update("update t_movie_hall set hallname=#{hallname},`row`=#{row},`column`=#{column} where hallId=#{hallId}")
    void upHall(MovieHallBean hall);
    //查询影厅
    @Select("select * from t_cinema")
    List<CinemaBean> getCinema();
    //根据登录的账号查询所属影院
    @Select("select * from t_cinema where name=#{name}")
    CinemaBean getCinema2(String name);
    //回显hall
    @Select("select * from t_movie_hall where hallId=#{hallId}")
    MovieHallBean getHallById(Integer hallId);
    //删除影厅
    @Delete("delete from t_movie_hall where hallId=#{hallId}")
    void delHall(Integer id);
    //新增影厅对应新增座位
    @Insert("insert into t_seat (seat_x,seat_y,hallId,status,cinemaid) values (#{i},#{j},#{hall.hallId},0,#{hall.cinemaId})")
    void addSeats(@Param("i") int i, @Param("j")int i1, @Param("hall")MovieHallBean hall);
    //修改影厅先删除对应的座位
    @Delete("delete from t_seat where hallId = #{hallId} and cinemaid = #{cinemaId}")
    void delSeats(MovieHallBean hall);

    //新增影院服务中间表
    void addCinemaService(@Param("arr")String[] split, @Param("cinemaId")Integer cinemaId);
}
